package com.ruoyi.articleCollect.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.articleCollect.mapper.ArticleCollectMapper;
import com.ruoyi.articleCollect.domain.ArticleCollect;
import com.ruoyi.articleCollect.service.IArticleCollectService;

import javax.annotation.Resource;

/**
 * 文章收藏Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-08
 */
@Service
public class ArticleCollectServiceImpl implements IArticleCollectService 
{
    @Resource
    private ArticleCollectMapper articleCollectMapper;

    /**
     * 查询文章收藏
     * 
     * @param id 文章收藏主键
     * @return 文章收藏
     */
    @Override
    public ArticleCollect selectArticleCollectById(Integer id)
    {
        return articleCollectMapper.selectArticleCollectById(id);
    }

    /**
     * 查询文章收藏列表
     * 
     * @param articleCollect 文章收藏
     * @return 文章收藏
     */
    @Override
    public List<ArticleCollect> selectArticleCollectList(ArticleCollect articleCollect)
    {
        return articleCollectMapper.selectArticleCollectList(articleCollect);
    }

    /**
     * 新增文章收藏
     * 
     * @param articleCollect 文章收藏
     * @return 结果
     */
    @Override
    public int insertArticleCollect(ArticleCollect articleCollect)
    {
        return articleCollectMapper.insertArticleCollect(articleCollect);
    }

    /**
     * 修改文章收藏
     * 
     * @param articleCollect 文章收藏
     * @return 结果
     */
    @Override
    public int updateArticleCollect(ArticleCollect articleCollect)
    {
        List<ArticleCollect> articleCollects = articleCollectMapper.selectArticleCollectList(articleCollect);
        System.out.println(articleCollects);
        if (articleCollects.isEmpty()){
            return articleCollectMapper.insertArticleCollect(articleCollect);
        }
        ArticleCollect articleCollect1 = articleCollects.get(0);
        if (articleCollect.getIsDeleted() == 0){
            articleCollect1.setIsDeleted(0);
        }else {
            articleCollect1.setIsDeleted(1);
        }
        return articleCollectMapper.updateArticleCollect(articleCollect1);
    }

    /**
     * 批量删除文章收藏
     * 
     * @param ids 需要删除的文章收藏主键
     * @return 结果
     */
    @Override
    public int deleteArticleCollectByIds(Integer[] ids)
    {
        return articleCollectMapper.deleteArticleCollectByIds(ids);
    }

    /**
     * 删除文章收藏信息
     * 
     * @param id 文章收藏主键
     * @return 结果
     */
    @Override
    public int deleteArticleCollectById(Integer id)
    {
        return articleCollectMapper.deleteArticleCollectById(id);
    }


}
